#include"process.h"
#include<unistd.h>
#include<time.h>
#include<stdlib.h>
typedef void (*call_t)(const char*,double,double);

double speed[] = {1.0,2.0,3.0,0.3,11.0};

void download(double total,call_t cb)
{
  srand(time(NULL));
  double current = 0.0;
  while(current <= total)
  {
    cb("下载中",total,current);
    usleep(10000);
    int radom = rand()%5;
    
    current+=speed[radom];

    if(current >= total)
    {
      current = total;
      cb("下载中",total,current);
      break;
    }
  }
}


void upload(double total,call_t cb)
{
  srand(time(NULL));
  double current = 0.0;
  while(current <= total)
  {
    cb("上传中",total,current);
    usleep(10000);
    int radom = rand()%5;
    
    current+=speed[radom];

    if(current >= total)
    {
      current = total;
      cb("上传中",total,current);
      break;
    }
  }
}



int main()
{
  download(1024.0,FlushProcess);
  printf("下载完成\n");
  upload(512.0,FlushProcess);
  printf("更新完成\n");
  //process();   //v1版本的进度条
  return 0;
}
